//
//  PhotoSetCollectionViewCell.m
//  item-NetEaseNews-tyw
//
//  Created by tyw on 15/10/2.
//  Copyright (c) 2015年 tyw. All rights reserved.
//

#import "PhotoSetCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@implementation PhotoSetCollectionViewCell {
    UIImageView* imgView;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        imgView = [[UIImageView alloc] initWithFrame:self.bounds];
        imgView.contentMode = UIViewContentModeScaleAspectFit;
        imgView.userInteractionEnabled = YES;
        [self.contentView addSubview:imgView];
        
        self.contentView.userInteractionEnabled = YES;
        
        [self _addGesture];
        
    }
    
    return self;
}

- (void)setModel:(PhotoModel *)model {
    if (_model != model) {
        _model = model;
        
        [self setNeedsLayout];
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    //图片
    [imgView sd_setImageWithURL:[NSURL URLWithString:_model.imgUrl]];
}

#pragma mark - 单击手势
//为图片添加单击手势,点击时发送通知，隐藏一些UI。
- (void)_addGesture {
    UIGestureRecognizer* tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgViewTapGestureAction)];
    [imgView addGestureRecognizer:tapRec];
}
- (void)imgViewTapGestureAction {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PhotoTapGestureNotification" object:nil];
}


@end
